package com.hbnu.iostream;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

public class OutputStreamDemo1 {
    public static void main(String[] args) {
        String path = "C:" + File.separator +"Users" + File.separator +"TX" + File.separator +"IdeaProjects" + File.separator +"javalean" + File.separator +"src" + File.separator +"com" + File.separator +"hbnu" + File.separator +"iostream" + File.separator +"test.txt";

        File file = new File(path);

        try {
            FileOutputStream outputStream = new FileOutputStream(file);
            String content = "hello, class2211";        //因为使用的是字节输出流，所以需要将字符数据转为字节数据
            byte[] bytes = content.getBytes();
            outputStream.write(bytes);                  //通过字节输出流向文件中写数据
            outputStream.close();
        }
        catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
